﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<MethodInfo>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Method Arguments - Open API Control Panel
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <fieldset>
        <legend>Method Manage &gt;
            <%= Model.METHOD_NAME %>
            &gt; UnSign Arguments</legend>
        <fieldset>
            <legend>Add</legend>
            <table border="0" cellspacing="0" width="100%">
                <tr>
                    <td width="100">
                        Name<font color="red">*</font>
                    </td>
                    <td>
                        <% =Html.TextBox("txtARGUMENT_NAME", "", new { @style = "width:300px" })%>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        Default Value
                    </td>
                    <td>
                        <% =Html.TextBox("txtARGUMENT_VALUE", "", new { @style = "width:300px" })%>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        DataType<font color="red">*</font>
                    </td>
                    <td>
                        <% =Html.TextBox("txtARGUMENT_DATATYPE", "", new { @style = "width:300px" })%>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        Desc
                    </td>
                    <td>
                        <% =Html.TextBox("txtARGUMENT_DESC", "", new { @style = "width:300px" })%>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        &nbsp;
                    </td>
                    <td>
                        <input type="button" id="btnAddArgument" name="btnAddArgument" value="Add Argument" />
                        <input type="button" id="btnBack" name="btnBack" value="Back" onclick="javascript:location.href='/Method/List';" />
                    </td>
                </tr>
            </table>
        </fieldset>
        <fieldset>
            <legend>List</legend>
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td width="140">
                        <strong>Name</strong>
                    </td>
                    <td width="80" align="center">
                        <strong>Default Value</strong>
                    </td>
                    <td width="120">
                        <strong>DataType</strong>
                    </td>
                    <td width="140">
                        <strong>Desc</strong>
                    </td>
                    <td align="center">
                        <strong>Manage</strong>
                    </td>
                </tr>
                <%
                    foreach (MethodUnSignArgumentInfo argument in ViewData["UnSignArguments"] as IList<MethodUnSignArgumentInfo>)
                    {
                %>
                <tr>
                    <td>
                        <%= argument.MethodUnSignArgumentPK.ARGUMENT_NAME%>
                    </td>
                    <td>
                        <%= argument.ARGUMENT_VALUE%>
                    </td>
                    <td>
                        <%= argument.ARGUMENT_DATATYPE%>
                    </td>
                    <td>
                        <%= argument.ARGUMENT_DESC%>
                    </td>
                    <td width="120" align="center">
                        [<a href="javascript:void(0);" onclick="javascript:Delete('<%=Model.METHOD_NAME %>','<%=argument.MethodUnSignArgumentPK.ARGUMENT_NAME %>');">Delete</a>]
                    </td>
                </tr>
                <%
                    }
                %>
            </table>
        </fieldset>
    </fieldset>

    <script type="text/javascript" language="javascript">

        //json: Submit
        $().ready(function() {
            $("#btnAddArgument").click(function() {

                if (confirm('Are you sure submit?')) {

                    var method_name = "<%= Model.METHOD_NAME %>";
                    var argument_name = $("input[name='txtARGUMENT_NAME']").val();
                    var argument_value = $("input[name='txtARGUMENT_VALUE']").val();
                    var argument_datatype = $("input[name='txtARGUMENT_DATATYPE']").val();
                    var argument_desc = $("input[name='txtARGUMENT_DESC']").val();

                    $("input[name='btnAddArgument']")[0].disabled = "disabled";
                    $("input[name='btnAddArgument']")[0].value = "Add Argument...";

                    $.post("/Method/AjaxAddUnSignArgument?" + new Date(), {
                        Action: "post",
                        method_name: method_name,
                        argument_name: argument_name,
                        argument_value: argument_value,
                        argument_datatype: argument_datatype,
                        argument_desc: argument_desc
                    }, function(result) {
                        if (result.FLAG) {
                            alert(result.DESC);
                            $("input[name='btnAddArgument']")[0].disabled = "";
                            $("input[name='btnAddArgument']")[0].value = "Add Argument";
                            location.href = "/Method/UnSignArguments/" + method_name;
                        }
                        else {
                            alert(result.DESC);
                            $("input[name='btnAddArgument']")[0].disabled = "";
                            $("input[name='btnAddArgument']")[0].value = "Add Argument";
                        }
                    })
                }
            })
        })


        function Delete(method_name, argument_name) {

            if (confirm('Are you sure delete?')) {

                $.post("/Method/AjaxDeleteUnSignArgument?" + new Date(), {
                    Action: "post",
                    method_name: method_name,
                    argument_name: argument_name
                }, function(result) {
                    if (result.FLAG) {
                        alert(result.DESC);
                        location.href = "/Method/UnSignArguments/" + method_name;
                    }
                    else {
                        alert(result.DESC);
                    }
                })
            }
        }
        
    </script>

</asp:Content>
